//
//  TableViewCell.m
//  HEClander
//
//  Created by User on 16/5/10.
//  Copyright © 2016年 User. All rights reserved.
//

#import "TableViewCell.h"
#import "DateTools.h"
#import "TableViewCellButton.h"

#define WIDTH [[UIScreen mainScreen] bounds].size.width
#define VIEW_WIDTH 58.0f*(WIDTH/414.0)
#define HEIGHT [[UIScreen mainScreen] bounds].size.height

NSMutableArray *ButtArr;
UIImageView *image;

@implementation TableViewCell
+ cellInitWithTableview:(UITableView *)tableview
{
    static NSString *str = @"cell";
    TableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:str];
    if (cell == nil) {
        cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
        cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        ButtArr = [[NSMutableArray alloc] init];
        
        [cell creatView];
    }
    return cell;
}

- (void)creatView
{
    for (int i = 0; i < 7 ; i ++) {
        TableViewCellButton *butt = [[TableViewCellButton alloc] initWithFrame:CGRectMake(VIEW_WIDTH*i+10*(WIDTH/414.0), 10*(HEIGHT/736.0), 40*(WIDTH/414.0), 40*(HEIGHT/736.0))];
        //butt.backgroundColor = [UIColor redColor];
        [butt setTitle:@"" forState:UIControlStateNormal];
        butt.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
        butt.titleLabel.textColor = UIColorFromRGB(0xdae2ff);
        [ViewTool setLableFont14:butt.titleLabel];
        if (i == 0) {
            _DateButton = butt;
        }if (i == 1) {
            _DateTwoButton = butt;
        }if (i == 2) {
            _DateThrButton = butt;
        }if (i == 3) {
            _DateForButton = butt;
        }if (i == 4) {
            _DateFifButton = butt;
        }if (i == 5) {
            _DateSixButton = butt;
        }if (i == 6) {
            _DateSevButton = butt;
        }
        
        [ButtArr addObject:butt];
        [self.contentView addSubview:butt];
        
    }
}

- (void)setTitData:(NSMutableArray *)array remaindArr:(NSMutableArray *)remaindArr withIndex:(int)index
{
//    NSLog(@"0000------------------------  %@  " , array);
    _Array = array;
    if (array.count != 0) {
        _ButtTitArr = array;
        NSDate *Today = [NSDate date];
        int todayDay = (int)[DateTools getDateInfobydate:Today].day;
        
        for (int i = 0; i < 7; i ++) {
            TableViewCellButton *butt = [ButtArr objectAtIndex:i];
            NSString *str = [array objectAtIndex:i+index*7];
            
            [butt setTitle:str forState:UIControlStateNormal];
            
            if ([str isEqualToString:@"今"]) {
                str = [NSString stringWithFormat:@"%d",todayDay];
                //            NSLog(@"0000------------------------  %d  " , [str intValue]);
                [butt setBackgroundImage:[UIImage imageNamed:@"HY_date_bg_today"] forState:UIControlStateNormal];
                
            }
            if ([str isEqualToString:@""]){
                butt.userInteractionEnabled = NO;
                [butt setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
                //            butt.roundView.hidden = YES;
            }
            
            butt.tag = [str intValue];
            
            if (![str isEqualToString:@""]){
                if (remaindArr.count != 0) {
                    for (NSString *remaind in remaindArr) {
                        
                        if (butt.tag == [remaind intValue]) {
                            butt.roundView.hidden = NO;
                            
                        }

                    }
               
                }
            }
        }
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
